
using System;
using System.Collections.Generic;
using System.Configuration;
using OF.Security.Properties;

namespace OF.Security.Utils
{
	public abstract class NamedConfigurationElementCollection<T> : ConfigurationElementCollection where T : NamedConfigurationElement, new()
	{
		public virtual T this[int index]
		{
			get
			{
				return (T)((object)base.BaseGet(index));
			}
		}

		public new T this[string name]
		{
			get
			{
				return (T)((object)base.BaseGet(name));
			}
		}

		public bool ContainsKey(string name)
		{
			return base.BaseGet(name) != null;
		}

		protected override object GetElementKey(ConfigurationElement element)
		{
			T t = (T)((object)element);
			return t.Name;
		}

		protected override ConfigurationElement CreateNewElement()
		{
			return Activator.CreateInstance<T>();
		}

		protected virtual T InnerGet(string name)
		{
			object obj = base.BaseGet(name);
			ExceptionHelper.FalseThrow<KeyNotFoundException>(obj != null, Resources.CanNotFindNamedConfigElement, new object[]
			{
				name
			});
			return (T)((object)obj);
		}
	}
}
